package com.freedom.sql.jdbc.utils;

/**
 * 
 * @author zhiqiang.liu[刘志强]
 * @2016年6月18日
 *
 */
public class MyConstants {
	//// https://dev.mysql.com/doc/internals/en/sending-more-than-16mbyte.html
	public static final int MAX_PACKET_LENGTH = 16 * 1024 * 1024;

	// 解析配置文件使用
	public static String CONFIG_FILE = System.getProperty("ourJdbcProperties", //
			"src/main/resources/ourJdbc.json");

	// 全局使用
	public static String SERVER = "server";
	public static String NETTY_PORT = "netty_server_port";
	public static String NETTY_BOSS = "netty_boss_number";
	public static String NETTY_WORKER = "netty_worker_number";
	public static String AUTH = "auth";
	public static String BIND = "bind";
	public static String LOGICDB = "logicDB";
	public static String LOGICTABLE = "logicTable";
	public static String PHYSICALDB = "physicalDB";
	public static String PHYSICALTABLE = "physicalTable";
	public static String WEIGHT = "weight";
	public static String ACTION = "action";
	public static String USERNAME = "user";
	public static String PASSWORD = "password";
	public static String MAXACTIVE = "maxActive";
	public static String MAXIDLE = "maxIdle";
	public static String MINIDLE = "minIdle";
	public static String MAXTOTAL = "maxTotal";
	public static String INITIALSIZE = "initialSize";
	public static String MAXWAIT = "maxWait";
	public static String TIMEBETWEENEVICTIONRUNSMILLIS = "timeBetweenEvictionRunsMillis";
	public static String MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis";
	public static String TESTONCREATE = "testOnCreate";
	public static String TESTWHILEIDLE = "testWhileIdle";
	public static String TESTONBORROW = "testOnBorrow";
	public static String TESTONRETURN = "testOnReturn";
	public static String BLOCKWHENEXHAUSTED = "blockWhenExhausted";
	public static String DB = "db";
	public static String TABLE = "table";
	public static String NAME = "name";
	public static String DATASOURCE = "dataSource";
	public static String IP = "ip";
	public static String PORT = "port";

	// 消费者的线程数
	public static String CONSUMER_WORKER = "consumer_worker_number";

	// handler使用

	// packet Number
	public static byte PACKET_NUMBER = 0;
	public static byte[] PACKET_NUMBER_BYTES = ByteUtils.writeByte(MyConstants.PACKET_NUMBER, 1);
	// 协议版本
	public static byte PROTOCOL_VERSION = 10;
	public static byte[] PROTOCOL_VERSION_BYTES = ByteUtils.writeByte(MyConstants.PROTOCOL_VERSION, 1);
	// server Description
	public static String SERVER_VERSION = "5.6.12";
	public static byte[] SERVER_VERSION_BYTES = ByteUtils.writeString(MyConstants.SERVER_VERSION);

	// server capabilities
	public static int SERVER_CAPABILITIES = 0xf7ff;// getServerCapabilities();
	public static byte[] SERVER_CAPABILITIES_BYTES = ByteUtils.writeInt(MyConstants.SERVER_CAPABILITIES, 2);

	// language
	public static int SERVER_LANGUAGE = 0x21;
	public static byte[] SERVER_LANGUAGE_BYTES = ByteUtils.writeInt(MyConstants.SERVER_LANGUAGE, 1);
	// server status
	public static int SERVER_STATUS = 2;
	public static byte[] SERVER_STATUS_BYTES = ByteUtils.writeInt(MyConstants.SERVER_STATUS, 2);

	// payload
	public static String PAYLOAD = "mysql_native_password";
	public static byte[] PAYLOAD_BYTES = ByteUtils.writeString(MyConstants.PAYLOAD);

	//
	protected static int getServerCapabilities() {
		int flag = 0;
		flag |= CapabilitiesUtils.CLIENT_LONG_PASSWORD;
		flag |= CapabilitiesUtils.CLIENT_FOUND_ROWS;
		flag |= CapabilitiesUtils.CLIENT_LONG_FLAG;
		flag |= CapabilitiesUtils.CLIENT_CONNECT_WITH_DB;
		// flag |= Capabilities.CLIENT_NO_SCHEMA;
		// flag |= Capabilities.CLIENT_COMPRESS;
		flag |= CapabilitiesUtils.CLIENT_ODBC;
		// flag |= Capabilities.CLIENT_LOCAL_FILES;
		flag |= CapabilitiesUtils.CLIENT_IGNORE_SPACE;
		flag |= CapabilitiesUtils.CLIENT_PROTOCOL_41;
		flag |= CapabilitiesUtils.CLIENT_INTERACTIVE;
		// flag |= Capabilities.CLIENT_SSL;
		flag |= CapabilitiesUtils.CLIENT_IGNORE_SIGPIPE;
		flag |= CapabilitiesUtils.CLIENT_TRANSACTIONS;
		// flag |= ServerDefs.CLIENT_RESERVED;
		flag |= CapabilitiesUtils.CLIENT_SECURE_CONNECTION;
		return flag;
	}

}
